package com.jyw.business.obstacles.wechat.controller;

import com.jyw.business.obstacles.domain.dto.web.OrderRejectUpdDto;
import com.jyw.business.obstacles.domain.dto.wechat.WxOrderPassUpdDto;
import com.jyw.business.obstacles.domain.dto.wechat.WxWorkOrderReviewPageDto;
import com.jyw.business.obstacles.domain.vo.wechat.WxWorkOrderReviewPageVO;
import com.jyw.business.obstacles.service.IObsOrderFaultService;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Created by ZhangCheng on 2023/09/06 （工单审核）
 */
@RestController
@RequestMapping("/wechat/workOrderReview")
@Api(tags = "微信工单审核")
public class ObsWxWorkOrderReviewController extends BaseController {

    @Resource
    private IObsOrderFaultService obsOrderFaultService;

    /**
     * 分页查询由我审核工单列表
     *
     * @param wxWorkOrderReviewPageDto
     * @return
     */
    @PostMapping("/pageList")
    @ApiOperation("分页查询由我审核工单列表")
    public TableDataInfo<WxWorkOrderReviewPageVO> pageList(@RequestBody WxWorkOrderReviewPageDto wxWorkOrderReviewPageDto) {
        startPage();
        List<WxWorkOrderReviewPageVO> list = obsOrderFaultService.pageWxProcessWorkOrder(wxWorkOrderReviewPageDto);
        return getDataTable(list);
    }

    /**
     * 微信工单审核通过
     *
     * @param dto
     * @return
     */
    @PostMapping("/pass")
    @ApiOperation("微信工单审核通过")
    @Log(title = "微信工单审核通过", businessType = BusinessType.UPDATE)
    public CommonResult pass(@Validated @RequestBody WxOrderPassUpdDto dto) {
        String orderNums = dto.getOrderNums();
        obsOrderFaultService.enact(orderNums);
        return CommonResult.success();
    }

    /**
     * 微信工单审核驳回
     *
     * @param dto
     * @return
     */
    @PostMapping("/reject")
    @ApiOperation("微信工单审核驳回")
    @Log(title = "微信工单审核驳回", businessType = BusinessType.UPDATE)
    public CommonResult reject(@Validated @RequestBody OrderRejectUpdDto dto) {
        obsOrderFaultService.reject(dto);
        return CommonResult.success();
    }
}
